<?php
include_once 'Zend/Db/Table.php';

Zend_Db_Table::setDefaultAdapter($db);

class Program extends Zend_Db_Table 
{
	protected $_name = 'partners_program';
	
	public function add($newProgram)
	{
		if ($programId = $this->insert($newProgram))
		{
			$this->_name = 'partners_firstlevel';
			$newFirstLevel['firstlevel_programid'] = $programId;
			$newFirstLevel['firstlevel_clickrate'] = 1;
			$newFirstLevel['firstlevel_leadrate'] = 1;
			$newFirstLevel['firstlevel_salerate'] = 1;
			$newFirstLevel['firstlevel_saletype'] = '$';
			$newFirstLevel['firstlevel_impressionrate'] = 0;
			$newFirstLevel['firstlevel_unitimpression'] = 1000;
			$newFirstLevel['firstlevel_recur_sale'] = 0;
			$newFirstLevel['firstlevel_recur_percentage'] = 1;
			$newFirstLevel['firstlevel_recur_period'] = 1;
			$this->insert($newFirstLevel);
			return true;
		}
		return false;
		
	}
	
	public function getProgramIdByUserId($userId)
	{
		$result = $this->fetchRow("program_merchantid = $userId");
		$result = $result->toArray();
		return $result['program_id'];
	}
}
?>